﻿using System;
using System.Drawing;
using System.Windows.Forms;

using Nextensions.Basic;

namespace Nextensions.GUI.Controls
{
	public partial class FormWithStatusStrip : Form
	{
		public FormWithStatusStrip()
		{
			InitializeComponent();
		}

        protected void SetStatus(IOperationResult result)
        {
            if (result.Success)
                SetStatusSuccess(result.Message);
            else
                SetStatusError(result.Message);
        }

		protected void SetStatus(string format, params object[] args)
		{
			SetStatus(String.Format(format, args));
		}

		protected void SetStatus(string text)
		{
			SetStatus(InfoLevel.Info, text);
		}

		protected void SetStatusSuccess(string format, params object[] args)
		{
			SetStatusSuccess(String.Format(format, args));
		}

		protected void SetStatusSuccess(string text)
		{
			SetStatus(InfoLevel.Success, text);
		}

		protected void SetStatusWarning(string format, params object[] args)
		{
			SetStatusWarning(String.Format(format, args));
		}

		protected void SetStatusWarning(string text)
		{
			SetStatus(InfoLevel.Warning, text);
		}

		protected void SetStatusError(string format, params object[] args)
		{
			SetStatusError(String.Format(format, args));
		}

		protected void SetStatusError(string text)
		{
			SetStatus(InfoLevel.Error, text);
		}

		protected void SetStatus(InfoLevel level, string format, params object[] args)
		{
			SetStatus(level, String.Format(format, args));
		}

		private void SetStatus(InfoLevel level, string text)
		{
			Color backgroundColor;

			switch (level)
			{
				case InfoLevel.Error:

					backgroundColor = Color.Salmon;
					break;

				case InfoLevel.Warning :
					
					backgroundColor = Color.Orange;
					break;

				case InfoLevel.Success :

					backgroundColor = Color.LightGreen;
					break;

				default:

					backgroundColor = SystemColors.Control;
					break;
			}

			StatusStrip.BackColor = backgroundColor;
			StatusLabel.Text = text;
		}
	}
}
